package com.bdqn.converter;
import org.springframework.core.convert.converter.Converter;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.logging.Logger;
    public class String2DateConverter implements Converter<String, Date> {
    private Logger logger = Logger.getLogger(String2DateConverter.class.getName());
    private String datePattern;//日期格式
        public String2DateConverter(String datePattern) {
            logger.info("加载String2DateConverter");
            this.datePattern = datePattern;
        }
        @Override
        public Date convert(String s) {
            Date date = null;
            try {
                date= (Date) new SimpleDateFormat(datePattern).parse(s);
            }catch (ParseException e) {
                e.printStackTrace();
            }
            return date;
        }
    }
